package cn.sciento.farm.devicemanager.quartz.service.impl;

import cn.sciento.farm.devicemanager.quartz.service.QuartzService;
import cn.sciento.farm.devicemanager.quartz.service.SchedulerService;
import com.alibaba.fastjson.JSON;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wumu
 * @version V1.0
 * @date 4/26/18
 * @time 9:37 PM
 */
@Service
public class QuartzServiceImpl implements QuartzService {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private SchedulerService schedulerService;

    @Override
    public boolean addJob(String jobName, String jobGroup, String cronExpression, Object params) throws SchedulerException {
        boolean en = false;
        en = schedulerService.addJob(jobName, jobGroup, cronExpression, JSON.toJSONString(params));

        return en;
    }

    @Override
    public boolean rescheduleJob(String jobName, String jobGroup, String cronExpression, Object params) throws SchedulerException {
        boolean en = false;
        en = schedulerService.rescheduleJob(jobName, jobGroup, cronExpression, JSON.toJSONString(params));

        return en;
    }

    @Override
    public boolean removeJob(String jobName, String jobGroup) throws SchedulerException {
        boolean result = false;
            result = schedulerService.removeJob(jobName, jobGroup);
        return result;
    }

    @Override
    public boolean pauseJob(String jobName, String jobGroup) throws SchedulerException {
        boolean result = false;
            result = schedulerService.pauseJob(jobName, jobGroup);

        return result;
    }

    @Override
    public boolean resumeJob(String jobName, String jobGroup) throws SchedulerException {
        boolean result = false;

            result = schedulerService.resumeJob(jobName, jobGroup);

        return result;
    }

    @Override
    public boolean triggerJob(String jobName, String jobGroup) throws SchedulerException {
        boolean result = false;

            result = schedulerService.triggerJob(jobName, jobGroup);

        return result;
    }
}
